/******************************************************************************
*  COPYRIGHT MorningCore CO.,LTD
******************************************************************************/

/*****************************************************************
* FileName::    <PUSCH_LayerMapper.c>
* version::     <1.0.0>
* Purpose:      <deal with Layer Mapper>
* Authors:      <shanshan, 2022-11-25>
* Notes:        <no>
******************************************************************/

/******************************************************************************
*  HISTORY OF CHANGES
*   <Date>          <Author>        <Version>       <DESCRIPTION>
*   ...             ...              ...            ....
******************************************************************************/

/******************************************************************************
*  INCLUDE FILES
******************************************************************************/
#include "../head/ue_tx_pusch_layermapper_fix.h"
/*----------- function definition-----------------------------------*/
/*****************************************************************************
* Function: PUSCH_LayerMapper()
* Purpose:  This function performs pusch's LayerMapper
* Relation:
Calls       : ....
Called by   : ....
* Params:
*   <Name>          <Type>      <In/Out>    <Description>
 CodewordNum        int8          In        number of Codewords
 LayerNum           int8          In        number of Layers
 PUSCH_RB_Num       int8          In        RB number of PUSCH
 PUSCH_SymNum       int8          In        number of SC-FDMA symbols for PUSCH
 DataIp[31680]      cmplx_frN     In/Out    input of Layers
 DataOp[12][1320]    cmplx_frN     In/Out    output of Layers
* Return:  void
* Note:    
*******************************************************************************/
void PUSCHLayerMapper_fix
(
    IN  stULParamTable *SimParam,
    IN cmplx_frN  *DataIp,
    OUT cmplx_frN *DataOp[MAXSYMNUM]
)
{
    /*variables definition*/
    int count_sc, data_symb_idx = 0, iSym, iRe, MaxScNum;

    MaxScNum = SimParam->PUSCH_RB_Num * SC_PER_RB;
    /* init */
    for (iSym = 0; iSym < MAXSYMNUM; iSym++)
    {
        for (iRe = 0; iRe < PUSCH_Max_RE; iRe++) //275*12
        {
            DataOp[iSym][iRe].re = 0;
            DataOp[iSym][iRe].im = 0;
        }
    }

    /* layer mapper */
    count_sc = 0;
    data_symb_idx = 0;
    for (iSym = 0; iSym < MAXSYMNUM; iSym++)
    {
        if (SimParam->u8_DMRS_Pos[iSym] == 0) // PUSCH Data
        {
            for (iRe = 0; iRe < MaxScNum; iRe++)
            {
                if (SimParam->pusch_re_flag[iSym][iRe] < 4) // -2: CSI2 punctring by ACK, -1: Data punctring by ACK, 0: UL-SCH, 1: ACK, 2:CSI1, 3: CSI2, 4: DMRS, 5: NULL, 6: SRS, 7:PT-RS
                {
                    DataOp[data_symb_idx][iRe] = DataIp[count_sc];
                    count_sc++;
                }
            }

            data_symb_idx++;
        } // end of if(SimParam->u8_DMRS_Pos[iSym] == 0) // PUSCH Data
    } //end of iSym
}
